package com.qfedu.dao;

import com.qfedu.model.Branch;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.Date;
import java.util.List;

public interface BranchDao {
    //根据pid查询
    @Select("select * from Branch where status = 1 and pid = #{pid}")
    List<Branch> findByPid(int pid);

    //跟据bid查询
    @Select("select * from Branch where status = 1 and bid = #{bid}")
    Branch findByBid(String bid);

    //添加
    @Insert("insert into branch (bname,pid,updatetime,status) values(#{bname},#{pid},#{updatetime},#{status})")
    void addBranch(Branch branch);

    //删除
    @Update("update branch set status = 0 where bid = #{bid}")
    void deleteBranch(String bid );

    //修改
    @Update("update branch set bname=#{bname},pid=#{pid},updatetime=#{updatetime},status=#{status} where bid = #{bid}")
    void updateBranch(Branch branch);

    //查询所有
    @Results(id = "findAllMap",value = {
            @Result(column = "bname",property = "bname"),
            @Result(column = "pid",property = "pid"),
            @Result(column = "updatetime",property = "updatetime"),
            @Result(column = "status",property = "status"),
            @Result(column = "bid",property = "bid"),
            @Result(column = "pid",property = "project",
                    one = @One(select = "com.qf.dao.ProjectDao.findByPid",fetchType = FetchType.EAGER)),
            @Result(column = "bid",property = "taskplans",
                    one = @One(select = "com.qf.dao.TaskplanDao.findByBid",fetchType = FetchType.EAGER))
    })
    @Select("select * from branch where status = 1")
    List<Branch> findAll();
}
